﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DispatchAssist.Weather.Interfaces;

namespace DispatchAssist.Weather.Entities
{
    [Serializable]
    class WeatherMapProvider : IWeatherMapProvider
    {
        public Guid WeatherProvideID { get; set; }
        public string ProviderID { get; set; }
        public string Name { get; set; }

        private IList<IWeatherMapType> type;
        public IList<IWeatherMapType> Types { get { return type ?? (type = new List<IWeatherMapType>()); } }

        [NonSerialized]
        private IList<IWeatherMapType> allTypes;
        public IList<IWeatherMapType> AllTypes { get { return allTypes ?? (allTypes = GetAllTypes().ToList()); } }

        private IEnumerable<IWeatherMapType> GetAllTypes()
        {
            if (type == null)
                yield break;

            foreach (var t in type)
            {
                yield return t;

                foreach (var c in GetChildTypes(t))
                {
                    yield return c;
                }
            }
        }

        private IEnumerable<IWeatherMapType> GetChildTypes(IWeatherMapType parentType)
        {
            foreach (var t in parentType.ChildTypes)
            {
                yield return t;

                foreach (var c in GetChildTypes(t))
                {
                    yield return c;
                }
            }

        }
    }
}
